package perf.store;

import java.io.File;

import perf.data.Setup;

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.config.Configuration;
import com.db4o.ta.TransparentActivationSupport;

public class ObjectStore {

	private ObjectContainer store;
	private ObjectList lister;
	private ObjectModify modifyer;
	
	public ObjectStore( File db ) {
		Configuration c = Db4o.newConfiguration();
		c.add( new TransparentActivationSupport() );

		//makes the changes to setup cascade to all it's content
		c.objectClass( Setup.class ).cascadeOnUpdate(true);
		
		store = Db4o.openFile( c, db.getPath() );

		lister = new ObjectList( store );
		modifyer = new ObjectModify( store, lister );
	}
	
	public ObjectList list( ) {
		return lister;
	}
	
	public ObjectModify modify( ) {
		return modifyer;
	}
	
	public void close( ) {
		if ( store != null ) {
			store.close();
		}
	}
}
